import wsgiref.handlers
from google.appengine.ext import webapp

import EventRecord
import RegistrationRecord

class ExportGuestList( webapp.RequestHandler ):

  def get( self ):
    self.response.headers['Content-Type'] = 'text/html'

    id = self.request.get('id')
    passcode = self.request.get('passcode')

    record = EventRecord.EventRecord \
      .gql( 'WHERE id = :1 AND passcode = :2', id, passcode ) \
      .get()
    if not record:
      self.response.out.write( 'Event not found!' )
      return
    guest_list = RegistrationRecord.RegistrationRecord \
      .gql( 'WHERE id = :1 ORDER BY email ASC', id )
    self.response.out.write( '<pre>' )

    last_guest = None
    for guest in guest_list:
      if last_guest is None or guest.email != last_guest.email:
        self.response.out.write( '"%s" &lt;%s&gt;\r\n' % (guest.name, guest.email) )
      last_guest = guest
    self.response.out.write( '</pre>' )
  # end of ExportGuestList.get

# end of class ExportGuestList
